package utility

import (
	"fmt"
	"github.com/gogf/gf/v2/os/gtime"
)

// TimeToDate 将时间戳转换为日期格式
func TimeToDate(timestamp int64, format string) string {
	if format == "" {
		format = "Y-m-d H:i:s"
	}
	return gtime.NewFromTimeStamp(timestamp).Format(format)
}

// DateToTime 将日期格式转换为时间戳
func DateToTime(date string, format string) int64 {
	if format == "" {
		format = "Y-m-d H:i:s"
	}
	t, err := gtime.StrToTimeFormat(date, format)
	if err != nil {
		fmt.Println("日期格式错误:", err)
		return 0
	}
	return t.Timestamp()
}
